<!DOCTYPE HTML>
<html>
<head>
<title>#Persistent | AutoHotkey</title>
<meta name="description" content="The #Persistent directive keeps a script permanently running (that is, until the user closes it or ExitApp is encountered)." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>#Persistent</h1>

<p>让脚本持续运行(即直到用户关闭或遇到 <a href="ExitApp.htm">ExitApp</a>).</p>

<pre class="Syntax"><span class="func">#Persistent</span></pre>
<p>如果在脚本的任意位置使用此指令, 那么脚本会在自动执行段(脚本的顶部) 结束后保持运行. 它可以用于当脚本包含<a href="SetTimer.htm">计时器</a>和/或<a href="Menu.htm">自定义菜单项</a>, 却不包含<a href="../Hotkeys.htm">热键</a>, <a href="Hotstrings.htm">热字串</a>或使用任何的 <a href="OnMessage.htm">OnMessage()</a> 或 <a href="Gui.htm">Gui</a> 的时候.</p>
<p>如果添加此指令到现有的脚本中, 您可能需要把一些或全部的 <a href="Exit.htm">Exit</a> 改为 <a href="ExitApp.htm">ExitApp</a>. 这是由于 <a href="Exit.htm">Exit</a> 不会终止持续运行的脚本; 它只会终止<a href="../misc/Threads.htm">当前线程</a>.</p>
<p><span class="ver">[v1.0.16+]</span>: 此指令同时也让脚本单实例运行. 要覆盖这种行为或改变单实例的方式, 请参阅 <a href="_SingleInstance.htm">#SingleInstance</a>.</p>
<h2>相关</h2>
<p><a href="_SingleInstance.htm">#SingleInstance</a>, <a href="SetTimer.htm">SetTimer</a>, <a href="Menu.htm">Menu</a>, <a href="Exit.htm">Exit</a>, <a href="ExitApp.htm">ExitApp</a></p>
<h2>示例</h2>
<pre class="NoIndent">#Persistent</pre>

</body>
</html>